﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Symbonix.NorSoNet.Framework;
using Symbonix.NorSoNet.Security.BLL.Membership;
using Symbonix.Library.DataStructure;
using Symbonix.NorSoNet.Security.DAL.Repositories;
using Symbonix.NorSoNet.Communication.BLL.Friendship;

public partial class FIND_FRIENDS : MemberBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    private void LoadData()
    {
        litSearchResult.Text = "Total 0 match found.";
    }
    protected void imbSeach_Click(object sender, ImageClickEventArgs e)
    {
        if (txtSearchFriend.Text.Trim() != "type friend name")
        {
            int total = 0;
            UserInfoDataRepository rep = new UserInfoDataRepository();
            
            //SystemUser sysUser = new UserFactory().GetUser() as SystemUser;
           // ReadWriteCustomCollection<IUser> users = sysUser.FindUser(txtSearchFriend.Text.Trim());
            repUsers.DataSource = rep.GetAll(txtSearchFriend.Text.Trim(), "", true, false, 0, 100, out total); ;
            repUsers.DataBind();

            litSearchResult.Text = "Total " + total.ToString()+" match found.";
        }
       
    }

    protected void repUsers_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "cmdAddFriends")
        {
            Workflow friendFlow = new Workflow();
            SystemMembershipFactory membershipFactory = new SystemMembershipFactory();
            IUser member = membershipFactory.GetCurrentUser();
            Symbonix.NorSoNet.Communication.BLL.Options.FriendRequestStatus status=friendFlow.SendFriendRequest(member.Id, Convert.ToInt32(e.CommandArgument.ToString()));
            if(status==Symbonix.NorSoNet.Communication.BLL.Options.FriendRequestStatus.Success)
            {
                remStatus.SetSuccessMessage("Friend request send");
            }
            else
            {
                remStatus.SetFailMessage("Error: " + status.ToString());
            }
        }
    }
}
